object CharFrequencyCounter {
  def main(args: Array[String]): Unit = {
    // 输入字符串
    val input = "一只小小狗"

    // 将字符串分割为字符数组
    val chars = input.toCharArray

    // 使用Map统计每个字符的出现次数
    val frequencyMap = chars.foldLeft(Map[Char, Int]()) { (map, char) =>
      map + (char -> (map.getOrElse(char, 0) + 1))
    }

    // 将Map中的键值对按照出现次数从多到少排序
    val sortedFrequency = frequencyMap.toSeq.sortBy(-_._2)

    // 输出结果
    sortedFrequency.foreach { case (char, count) =>
      println(s"$char  $count")
    }
  }
}